<?php
/**
 * Rph_model Class
 *
 */
class Stok_model extends CI_Model {
	/**
	 * Constructor
	 */
	function Stok_model()
		{
			parent::__construct();
		}
		
	function get_stok_titik_pasok($id_titik_pasok, $id_sapi, $revisi){//echo "id titik pasok: ".$id_titik_pasok.", id sapi: ".$id_sapi.", revisi: ".$revisi;
		$result = $this->db->select('SUM(JUMLAH) as JUMLAH')
				->from('stok')
				->join('titik_pasok', 'stok.ID_TITIK_PASOK=titik_pasok.ID_TITIK_PASOK')
				->where('stok.ID_TITIK_PASOK', $id_titik_pasok)
				->where('stok.ID_SAPI', $id_sapi)
				->where('stok.REVISI', $revisi)
				->get();
		
		$stok = $result->result_array();
		if($stok[0]['JUMLAH'] > 0){
			return $stok[0]['JUMLAH'];
		} else {
			return 0;
		}
	}
	
	function insert_to_stok($arr){
		$this->db->insert('stok', $arr);
	}
	
	function get_alasan_by_id($id){
		return $this->db->select('*')
				->from('alasan_perubahan')
				->where('ID_ALASAN_PERUBAHAN',$id)
				->get()->row();
	}
}
// END Rph_model Class

/* End of file Rph_model.php */ 
/* Location: ./system/application/model/rph_model.php */